package com.cheer.controller;

import com.cheer.common.Page;
import com.cheer.common.Result;
import com.cheer.dto.OaLearnClassAddDTO;
import com.cheer.dto.OaLearnClassUpdateDTO;
import com.cheer.dto.OaMatrixClassAddDTO;
import com.cheer.dto.OaMatrixClassUpdateDTO;
import com.cheer.service.OaAdminService;
import com.cheer.service.OaLearnClassService;
import com.cheer.service.OaMatrixClassService;
import com.cheer.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/matrix/class")
public class OaMatrixClassController {

    @Autowired
    private OaMatrixClassService oaMatrixClassService;

    @ApiOperation("添加矩阵分类")
    @PostMapping("/add")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result add(@RequestBody @Valid OaMatrixClassAddDTO matrixClassAddDTO) {
        oaMatrixClassService.add(matrixClassAddDTO);
        return Result.success();
    }

    @ApiOperation("查询一级分类")
    @GetMapping("/sub")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result<List<SimpleObjectVO>> sub() {
        return Result.success(oaMatrixClassService.sub());
    }

    @ApiOperation("查询矩阵分类列表")
    @GetMapping("/list")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result<Page<OaMatrixClassListVO>> list(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return Result.success(oaMatrixClassService.list(pageNum, pageSize));
    }

    @ApiOperation("删除矩阵分类")
    @GetMapping("/delete")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result delete(@RequestParam Integer id) {
        oaMatrixClassService.delete(id);
        return Result.success();
    }

    @ApiOperation("查询矩阵分类详情")
    @GetMapping("/info")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result<OaMatrixClassInfoVO> info(@RequestParam Integer id) {
        return Result.success(oaMatrixClassService.info(id));
    }

    @ApiOperation("修改矩阵分类")
    @PostMapping("/update")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result update(@RequestBody @Valid OaMatrixClassUpdateDTO matrixClassUpdateDTO) {
        oaMatrixClassService.update(matrixClassUpdateDTO);
        return Result.success();
    }
}
